import * as base from "./base.js";
import instance from './request.js';
import { animate } from './animate.js';
import { $, $$ } from './base.js';


window.addEventListener('load', function () {

    //跳转到发布房源页面
    if (localStorage.getItem('identity') == 2) {
        $('.add_fangyuan').style.display = 'block';
    }

    base.navbox();
    base.debounce(base.avatarimg);


    //判断是否已收藏
    if (localStorage.getItem('data-lazynum') == 0) {
        $('.collect_but_no').style.display = 'block';
        $('.collect_span').innerHTML = '收藏';
    } else {
        $('.collect_but_yes').style.display = 'block';
        $('.collect_span').innerHTML = '已收藏';
    }



    //人数
    let addrec = 0;

    let detailpicarr = [];
    let detailid = localStorage.getItem('detailid');
    //房源详情页
    instance.get(`/home/detail/${detailid}`, {
        headers: {
            'Authorization': window.localStorage.getItem('token'),
            'Content-Type': 'application/json',
        }
    }).then(response => {

        let detailarr = response.data.data;
        detailpicarr = detailarr.pictures;
        console.log(detailarr);

        $('.home_title').innerHTML = detailarr.title;
        $('.homeintroduce>div:nth-child(2)').innerHTML = detailarr.introduce;
        $('.order_money span:nth-child(1)').innerHTML = detailarr.price;
        $('.order_tenant').innerHTML = detailarr.tenant;
        addrec = detailarr.tenant;
        $('.userimg img').src = detailarr.user.avatarURL;
        $('.userthing .username').innerHTML = detailarr.user.name;
        $('.evaluate_star').style.width = detailarr.star * 22 + 'px';
        $('.orderstars').style.width = detailarr.star * 10 + 'px';


        if (detailarr.labels) {
            detailarr.labels.forEach(function (value, index, array) {
                let labstr = `<div class="homelabel">${detailarr.labels[index].name}</div>`
                $('.homelabels').insertAdjacentHTML('beforeend', labstr);
            })
        }

        let picturelen = detailarr.pictures.length;
        if (picturelen >= 5) {
            picturelen = 5;
        }


        for (let i = 0; i < picturelen; i++) {
            $$('.detail_pic_1 img')[i].src = detailarr.pictures[i];
            $$('.detail_pic_1 img')[i].style.filter = 'blur(0)';
        }


    })



    //点击看大图
    $('.detail_pic').addEventListener('click', function (event) {
        const targetElement = event.target;
        console.log(1000 * targetElement.parentNode.getAttribute('id') + 'px');
        $('.d_banner ul').style.left = -1000 * (targetElement.parentNode.getAttribute('id') - 1) + 'px';
        num = targetElement.parentNode.getAttribute('id') - 1;

        let d_banner = $('.d_banner ul');



        if (targetElement.parentNode.classList.contains('detail_pic_1')) {
            $('.detailmask').style.display = 'block';
            console.log(detailid);

            instance.get(`/home/detail/${detailid}`, {
                headers: {
                    'Authorization': window.localStorage.getItem('token'),
                    'Content-Type': 'application/json',
                }
            }).then(response => {
                detailpicarr = response.data.data.pictures;


                d_banner.style.width = (detailpicarr.length + 1) * 1000 + 'px';

                console.log(d_banner.style.width);

                detailpicarr.forEach(function (value, index, array) {
                    let li = `<li>
                                <img src="${detailpicarr[index]}" alt="">
                            </li>`
                    d_banner.insertAdjacentHTML('beforeend', li);
                });


                let str = `<li>
                                <img src="${detailpicarr[0]}" alt="">
                            </li>`
                d_banner.insertAdjacentHTML('beforeend', str);

            })

        }
    });

    var num = 0;
    var flag = true;

    $('.d_right').addEventListener('click', function () {
        if (flag) {
            flag = false;
            //如果走到了最后复制的一张图片，此时我们的ul 要快速复原 left 改为 0
            if (num == detailpicarr.length - 1) {
                $('.d_banner ul').style.left = 0;
                num = 0;
            }
            num++;
            animate($('.d_banner ul'), -num * 1000, function () {
                flag = true;
            });

        }
    });

    $('.d_left').addEventListener('click', function () {
        if (flag) {
            flag = false;
            //如果走到了最后复制的一张图片，此时我们的ul 要快速复原 left 改为 0
            if (num == 0) {
                num = detailpicarr.length - 1;
                $('.d_banner ul').style.left = -num * middleWidth + 'px';
            }
            num--;
            animate($('.d_banner ul'), -num * 1000, function () {
                flag = true;
            });
        }
    });

    $('.d_close').addEventListener('click', function () {
        $('.detailmask').style.display = 'none';
    })



    //固定订单
    document.addEventListener('scroll', function () {
        if (window.pageYOffset >= 600) {
            $('.order').style.position = 'fixed';
            $('.order').style.top = '130px';
            $('.order').style.right = '281px';
            $('.order').style.zIndex = '1';
        } else {
            $('.order').style.position = 'absolute';
            $('.order').style.top = '600px';
            $('.order').style.right = '270px';
        }
    })


    //获取房源评价
    instance.get(`/home/review/${detailid}`, {
        params: {
            offset: 0,
            limit: 8,
        }
    }).then(response => {
        console.log(response);
        let evaluatearr = response.data.data.reviewList;

        if (evaluatearr.length) {
            evaluatearr.forEach(item => {
                let str = `<div class="evaluates_li">
                <span class="evaluates_stars" style="width:${(item.star) * 10}px;"></span>
                <div class="evaluates_li-t">
                    <div class="evaluates_img">
                        <img src="${item.user.avatarUrl ? item.user.avatarUrl : "https://z1.muscache.cn/defaults/user_pic-50x50.png?v=3&im_w=240"}" alt="">
                    </div>
                    <div>
                        <div class="evaluates_name">${item.user.username}</div>
                        <div class="evaluates_time" style="font-size: 14px; font-weight: normal;">
                        ${item.updateAt.substr(0, 10)}</div>
                    </div>
                </div>
                <div class="evaluates_li-b">
                    <div class="more_ellipsis">
                    ${item.content}
                    </div>
                </div>
            </div>`

                $('.evaluates').insertAdjacentHTML('beforeend', str);
            })


            $('.userevaluate span').innerHTML = evaluatearr.length;
            $('.order_pinglun').innerHTML = evaluatearr.length;
        }
    }).catch(error => {
        console.error(error)
    })


    //日期选择器
    //月份
    const currentMonth = document.querySelector('.date_t');
    const daysContainer = document.querySelector('.days');

    // 获取当前日期
    const currentDate = new Date();

    // 月份名称
    const monthNames = [
        '1月', '2月', '3月', '4月', '5月', '6月',
        '7月', '8月', '9月', '10月', '11月', '12月'
    ];

    // 入住日期
    let checkInDate = null;

    // 渲染日历
    function renderCalendar(year, month) {
        // 清空日历
        daysContainer.innerHTML = '';

        // 设置当前月份
        currentMonth.textContent = `${year}年${monthNames[month]}`;

        // 获取当前月份的第一天
        const firstDay = new Date(year, month, 1);

        // 获取当前月份的最后一天
        const lastDay = new Date(year, month + 1, 0);

        // 获取当前月份的天数
        const numDays = lastDay.getDate();

        // 获取当前月份的第一天是星期几
        const firstDayOfWeek = firstDay.getDay();

        // 创建空白格子
        for (let i = 0; i < firstDayOfWeek; i++) {
            const emptyCell = document.createElement('button');
            emptyCell.disabled = true;
            emptyCell.style.border = 0;
            daysContainer.appendChild(emptyCell);
        }

        // 创建日期格子
        for (let day = 1; day <= numDays; day++) {
            const cell = document.createElement('button');
            cell.textContent = day;
            cell.classList.add('date-day');
            cell.addEventListener('click', function () {
                const selectedDate = new Date(year, month, day);
                if (checkInDate && selectedDate < checkInDate) {
                    console.log(3);
                    return; // 如果选择的日期在入住日期之前，则不执行任何操作
                }
                if (!checkInDate) {
                    checkInDate = selectedDate; // 设置入住日期
                }
                const formattedDate = selectedDate.toISOString().split('T')[0];
                // dateInput.value = formattedDate;
            });
            daysContainer.appendChild(cell);
        }
    }


    // 初始化日历
    renderCalendar(currentDate.getFullYear(), currentDate.getMonth());

    let clear_num1 = 0;
    function check(obj, obj1, num1, num2) {
        //日期选择
        instance.get(`/order/${detailid}`)
            .then(response => {
                let datearr = response.data.data;
                console.log(response.data);


                if (datearr != null) {
                    console.log('哈哈哈');
                    datearr.forEach(function (value, index, array) {
                        let start = datearr[index].startTime.split('-');
                        let end = datearr[index].endTime.split('-');

                        if (start[0] == end[0] && end[0] == currentDate.getFullYear() && parseInt(start[1]) == parseInt(end[1]) && parseInt(end[1]) == currentDate.getMonth() + 1) {
                            for (let i = parseInt(start[2]) - 1 + new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() - 1; i <= parseInt(end[2]) - 1 + new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() - 1; i++) {
                                $$('.days button')[i + 1].style.textDecoration = 'line-through';
                                $$('.days button')[i + 1].style.color = '#787878';
                                $$('.days button')[i + 1].style.cursor = 'default';
                                $$('.days button')[i + 1].classList.remove('date-day');
                                $$('.days button')[i + 1].classList.add('line_through');
                            }
                        } else if (parseInt(start[1]) < parseInt(end[1])) {
                            if (parseInt(start[1]) == currentDate.getMonth() + 1 && parseInt(end[1]) != currentDate.getMonth() + 1) {
                                for (let i = parseInt(start[2]) - 1 + new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() - 1; i <= new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() - 1 + parseInt(end[2]) + new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0).getDate(); i++) {
                                    $$('.days button')[i + 1].style.textDecoration = 'line-through';
                                    $$('.days button')[i + 1].style.color = '#787878';
                                    $$('.days button')[i + 1].style.cursor = 'default';
                                    $$('.days button')[i + 1].classList.remove('date-day');
                                    $$('.days button')[i + 1].classList.add('line_through');
                                }
                            } else if (parseInt(start[1]) != currentDate.getMonth() + 1 && parseInt(end[1]) == currentDate.getMonth() + 1) {
                                for (let i = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() - 1; i <= parseInt(end[2]) + (new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() - 1) - 1; i++) {
                                    $$('.days button')[i + 1].style.textDecoration = 'line-through';
                                    $$('.days button')[i + 1].style.color = '#787878';
                                    $$('.days button')[i + 1].style.cursor = 'default';
                                    $$('.days button')[i + 1].classList.remove('date-day');
                                    $$('.days button')[i + 1].classList.add('line_through');
                                }
                            } else if (parseInt(start[1]) <= currentDate.getMonth() + 1 && parseInt(end[1]) >= currentDate.getMonth() + 1) {
                                console.log(666);
                                for (let i = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() - 1; i <= new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0).getDate(); i++) {
                                    $$('.days button')[i + 1].style.textDecoration = 'line-through';
                                    $$('.days button')[i + 1].style.color = '#787878';
                                    $$('.days button')[i + 1].style.cursor = 'default';
                                    $$('.days button')[i + 1].classList.remove('date-day');
                                    $$('.days button')[i + 1].classList.add('line_through');
                                }
                            }
                        }
                    })
                }

                function checkhover(index, value) {
                    $$('.date-day').forEach(function (value, index, array) {
                        $$('.date-day')[index].style.color = '#222';
                        $$('.date-day')[index].style.background = '#fff';
                        $$('.date-day')[index].classList.add('date-day_1');
                    })



                    $$('.date-day')[index].style.color = '#fff ';
                    $$('.date-day')[index].style.background = '#00a699';
                    $$('.date-day')[index].classList.remove('date-day_1');


                    $(`${obj}>div:nth-child(2)`).innerHTML = currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1).toString().padStart(2, '0') + '-' + value.textContent.trim().padStart(2, '0');

                    if (clear_num1 == 0) {
                        console.log($(`${obj}>div:nth-child(2)`).innerHTML);
                        checkInDate = new Date($(`${obj}>div:nth-child(2)`).innerHTML);
                        value.classList.add('selected'); // 添加选中的入住日期的样式类名
                    }

                }

                $$('.date-day').forEach(function (value, index, array) {
                    $$('.date-day')[index].onclick = function () {
                        checkhover(index, value);
                        clear_num1 = 1;
                    }
                })


                $('.date_selector').style.display = 'block';
                console.log(checkInDate);


                $(`${obj}>div:nth-child(2)`).style.background = 'rgb(153, 237, 230)';
                $(`${obj}>div:nth-child(2)`).style.borderColor = 'rgb(153, 237, 230)';
                $(`${obj}>div:nth-child(2)`).style.color = 'rgb(0, 122, 135)';

                $(`${obj1}>div:nth-child(2)`).style.background = '0';
                $(`${obj1}>div:nth-child(2)`).style.borderColor = '0';
                $(`${obj1}>div:nth-child(2)`).style.color = '#787878';


                check_num = num1;
                check_out_num = num2;
            })

    }



    let check_num = 0;
    $('.check_in_mask').addEventListener('click', function () {
        if (check_num == 0) {
            check('.check_in', '.check_out', 1, 0);
            $$('.days button').forEach(function (value, index) {
                const selectedDate = new Date($('.check_out>div:nth-child(2)').innerHTML);

                const selectedDay = selectedDate.getDate();

                if (index > selectedDay - 1) {
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].style.textDecoration = 'line-through';
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].style.color = '#787878';
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].style.cursor = 'default';
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].classList.remove('date-day');
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].classList.remove('date-day_1');
                }

                for (let i = 0; i < $$('.line_through').length; i++) {

                }
                $$('.line_through')
            });
            // 上一个月份按钮点击事件处理逻辑
            $('.date_left').onclick = function () {
                currentDate.setMonth(currentDate.getMonth() - 1);
                renderCalendar(currentDate.getFullYear(), currentDate.getMonth());
                check('.check_in', '.check_out', 1, 0);
            };

            // 下一个月份按钮点击事件处理逻辑
            $('.date_right').onclick = function () {
                currentDate.setMonth(currentDate.getMonth() + 1);
                renderCalendar(currentDate.getFullYear(), currentDate.getMonth());
                check('.check_in', '.check_out', 1, 0);
            };
        }
    })

    let check_out_num = 0;
    $('.check_out_mask').addEventListener('click', function () {
        if (check_out_num == 0) {
            check('.check_out', '.check_in', 0, 1);
            $$('.days button').forEach(function (value, index) {
                const selectedDate = new Date($('.check_in>div:nth-child(2)').innerHTML);

                const selectedDay = selectedDate.getDate();

                if (index < selectedDay - 1) {
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].style.textDecoration = 'line-through';
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].style.color = '#787878';
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].style.cursor = 'default';
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].classList.remove('date-day');
                    $$('.days button')[new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay() + index].classList.remove('date-day_1');
                }
            });
            // 上一个月份按钮点击事件处理逻辑
            $('.date_left').onclick = function () {
                currentDate.setMonth(currentDate.getMonth() - 1);
                renderCalendar(currentDate.getFullYear(), currentDate.getMonth());
                check('.check_out', '.check_in', 0, 1);
            };

            // 下一个月份按钮点击事件处理逻辑
            $('.date_right').onclick = function () {
                currentDate.setMonth(currentDate.getMonth() + 1);
                renderCalendar(currentDate.getFullYear(), currentDate.getMonth());
                check('.check_out', '.check_in', 0, 1);
            };
        }
    })


    function blur(event, obj) {
        $(`${obj}>div:nth-child(2)`).style.background = '0';
        $(`${obj}>div:nth-child(2)`).style.borderColor = '0';
        $(`${obj}>div:nth-child(2)`).style.color = '#787878';
    }
    document.addEventListener("click", function (event) {
        // 如果点击的是输入框或其子元素，则不做任何处理
        if (!(event.target === $('.check_in_mask') || event.target === $('.check_out_mask') ||
            event.target === $('.date_selector') || $('.date_selector').contains(event.target))) {
            $('.date_selector').style.display = 'none';
            blur(event, '.check_in');
            blur(event, '.check_out');
            check_num = 0;
            check_out_num = 0;
        }
    });




    //人数
    let order_peo_num = 0;
    $('.order_peo').addEventListener('click', function (event) {
        console.log(1);
        if (event.target === $('.order_peo') || $('.order_peo').contains(event.target)) {
            console.log(2);
            console.log(order_peo_num);
            if (order_peo_num == 0) {
                $('.renshubox').style.display = 'block';
                $('.ren_down').style.display = 'none';
                $('.ren_up').style.display = 'block';
                if ($('.babys').style.display == 'none') {
                    $('.adults').style.background = 'rgb(153, 237, 230)';
                    $('.adults').style.color = 'rgb(0, 122, 135)';
                } else {
                    $('.order_peo_num').style.background = 'rgb(153, 237, 230)';
                    $('.order_peo_num').style.color = 'rgb(0, 122, 135)';
                }

                order_peo_num = 1;
            } else {
                $('.renshubox').style.display = 'none';
                $('.ren_down').style.display = 'block';
                $('.ren_up').style.display = 'none';
                if ($('.babys').style.display == 'none') {
                    $('.adults').style.background = '#fff';
                    $('.adults').style.color = '#222';
                } else {
                    $('.order_peo_num').style.color = '#222';
                    $('.order_peo_num').style.background = '#fff';
                }

                order_peo_num = 0;
            }
        }

    })
    $('.close_renshu').addEventListener('click', function () {
        $('.order_peo').click();
    })


    document.addEventListener("click", function (event) {
        // 如果点击的是输入框或其子元素，则不做任何处理
        if (!(event.target === $('.order_peo') || $('.order_peo').contains(event.target) ||
            event.target === $('.renshubox') || $('.renshubox').contains(event.target))) {
            $('.renshubox').style.display = 'none';
            $('.ren_down').style.display = 'block';
            $('.ren_up').style.display = 'none';
            if ($('.babys').style.display == 'none') {
                $('.adults').style.background = '#fff';
                $('.adults').style.color = '#222';
            } else {
                $('.order_peo_num').style.color = '#222';
                $('.order_peo_num').style.background = '#fff';
            }

            order_peo_num = 0;
        }

    });


    let renshunum = 1;
    function ren_r(index, num) {
        $$('.ren_add')[index].addEventListener('click', function () {
            if (renshunum == addrec - 1) {
                $$('.ren_add')[0].style.border = '1px solid #b2dadb';
                $$('.ren_add svg')[0].style.fill = '#b2dadb';
                $$('.ren_add')[1].style.border = '1px solid #b2dadb';
                $$('.ren_add svg')[1].style.fill = '#b2dadb';
                $$('.ren_tenant')[index].innerHTML++;
                if ($$('.ren_tenant')[index].innerHTML != num) {
                    $$('.ren_reduce')[index].style.border = '1px solid #008489';
                    $$('.ren_reduce svg')[index].style.fill = '#008489';
                }

                $('.peo_num').innerHTML++;
                renshunum++;
            } else if (renshunum < addrec - 1) {
                $$('.ren_reduce')[index].style.border = '1px solid #008489';
                $$('.ren_reduce svg')[index].style.fill = '#008489';
                $$('.ren_tenant')[index].innerHTML++;
                $('.peo_num').innerHTML++;
                renshunum++;
            }


        })
    }
    ren_r(0, 1);
    ren_r(1, 0);


    function ren_l(index, num) {
        $$('.ren_reduce')[index].addEventListener('click', function () {
            if (renshunum > 1 && ($$('.ren_tenant')[index].innerHTML > num + 1)) {
                console.log($$('.ren_tenant')[index].innerHTML);
                console.log(num);
                $$('.ren_add')[0].style.border = '1px solid #008489';
                $$('.ren_add svg')[0].style.fill = '#008489';
                $$('.ren_add')[1].style.border = '1px solid #008489';
                $$('.ren_add svg')[1].style.fill = '#008489';

                $$('.ren_tenant')[index].innerHTML--;
                $('.peo_num').innerHTML--;
                renshunum--;
            } else if ($$('.ren_tenant')[index].innerHTML == num + 1) {
                $$('.ren_reduce')[index].style.border = '1px solid #b2dadb';
                $$('.ren_reduce svg')[index].style.fill = '#b2dadb';
                $$('.ren_tenant')[index].innerHTML--;
                $('.peo_num').innerHTML--;
                renshunum--;
            }
        })
    }
    ren_l(0, 1);
    ren_l(1, 0);



    $$('.ren_add')[2].addEventListener('click', function () {
        if ($$('.ren_tenant')[2].innerHTML == 5 - 1) {
            $$('.ren_add')[2].style.border = '1px solid #b2dadb';
            $$('.ren_add svg')[2].style.fill = '#b2dadb';
            $('.babys span').innerHTML++;
            $$('.ren_tenant')[2].innerHTML++;
            return;
        } else if ($$('.ren_tenant')[2].innerHTML < 5 - 1) {
            $('.babys').style.display = 'block';
            $$('.ren_reduce')[2].style.border = '1px solid #008489';
            $$('.ren_reduce svg')[2].style.fill = '#008489';
            $('.babys span').innerHTML++;
            $$('.ren_tenant')[2].innerHTML++;
        }
    })
    $$('.ren_reduce')[2].addEventListener('click', function () {
        if ($$('.ren_tenant')[2].innerHTML == 1) {
            $('.babys').style.display = 'none';
            $$('.ren_reduce')[2].style.border = '1px solid #b2dadb';
            $$('.ren_reduce svg')[2].style.fill = '#b2dadb';
            $('.babys span').innerHTML--;
            $$('.ren_tenant')[2].innerHTML--;
            return;
        } else if ($$('.ren_tenant')[2].innerHTML > 1) {
            $$('.ren_add')[2].style.border = '1px solid #008489';
            $$('.ren_add svg')[2].style.fill = '#008489';
            $('.babys span').innerHTML--;
            $$('.ren_tenant')[2].innerHTML--;
        }
    })






    $('.orderbutton').addEventListener('click', base.debounce(function () {
        if ($('.ren_tenant').innerHTML && $('.check_in_box').innerHTML != '入住日期' && $('.check_out_box').innerHTML != '退房日期') {
            instance.post('/order', {
                homeId: detailid,
                tenant: $('.peo_num').innerHTML,
                startTime: $('.check_in_box').innerHTML,
                endTime: $('.check_out_box').innerHTML
            }, {
                headers: {
                    'Authorization': window.localStorage.getItem('token'),
                    'Content-Type': 'application/json',
                }
            }).then(response => {
                console.log(response);
                base.tooltipBox('', '预定成功!', '1');
                $('.babys').style.display = 'none';
                renshunum = 1;
                $('.peo_num').innerHTML = 1;
                $$('.ren_tenant')[0].innerHTML = 1;
                $$('.ren_tenant')[1].innerHTML = 0;
                $$('.ren_tenant')[2].innerHTML = 0;

                for (let i = 0; i < 3; i++) {
                    $$('.ren_add')[i].style.border = '1px solid #008489';
                    $$('.ren_add svg')[i].style.fill = '#008489';
                    $$('.ren_reduce')[i].style.border = '1px solid #b2dadb';
                    $$('.ren_reduce svg')[i].style.fill = '#b2dadb';
                }


                location.href = 'order.html';
            }).catch(error => {
                console.error(error)
            })
        }
    }))


    //点击头像跳转到房东资料页面
    $('.userimg').addEventListener('click', function () {
        location.href = 'landlord.html';
    })


})